from django.urls import path, include

from web.views import (account, home, project, wiki, file, setting, issues,
                       dashboard, statistics)

# 单独项目有关url
manage_patterns = [
    # dashboard
    path('dashboard/', dashboard.dashboard, name='dashboard'),
    path('dashboard/issues/chart/',
         dashboard.issues_chart,
         name='issues_chart'),

    # issues
    path('issues/', issues.issues, name='issues'),
    path('issues/detail/<int:issues_id>/',
         issues.issues_detail,
         name='issues_detail'),
    path('issues/record/<int:issues_id>/',
         issues.issues_record,
         name='issues_record'),
    path('issues/change/<int:issues_id>/',
         issues.issues_change,
         name='issues_change'),
    path('issues/invite/url/', issues.invite_url, name='invite_url'),

    # settings
    path('settings/', setting.setting, name='settings'),
    path('setting/delete/', setting.delete, name='setting_delete'),

    # statistics
    path('statistics/', statistics.statistics, name='statistics'),
    path('statistics/priority',
         statistics.statistics_priority,
         name='statistics_priority'),
    path('statistics/project/user/',
         statistics.statistics_project_user,
         name='statistics_project_user'),

    # file
    path('file/', file.file, name='file'),
    path('file/delte/', file.file_delete, name='file_delete'),
    path('cos/credential/', file.cos_credential, name='cos_credential'),
    path('file/post/', file.file_post, name='file_post'),
    path('file/download/<int:file_id>/',
         file.file_download,
         name='file_download'),

    # wiki 相关的URL设计中，并没有视图给 /manage/3/wiki/2/ 这类url匹配视图
    # 函数,不过使用GET方法时由 /manage/2/wiki/?wiki_id=<wiki_id> 可以访问
    # wiki内容. 地址中没有包含 wiki_id 参数时，则是由 wiki.html 文件末尾的
    # ajax请求获取项目所有的wiki信息，并利用 jquery 生成了对应的目录，目录
    # 每个标题都是 a 标签，且 href 属性正是如 /manage/3/wiki/?wiki_id=3 这
    # 类地址

    # 如此利用Ajax配合urls.py文件中的路由分发设计，可以实现wiki的整体展示或具体文档
    # 内容展示，而且仅仅使用了一个视图函数 wiki.wiki
    path('wiki/', wiki.wiki, name='wiki'),
    path('wiki/add/', wiki.wiki_add, name='wiki_add'),
    path('wiki/catalog/', wiki.wiki_catalog, name='wiki_catalog'),
    path('wiki/delete/<int:wiki_id>/', wiki.wiki_delete, name='wiki_delete'),
    path('wiki/edit/<int:wiki_id>/', wiki.wiki_edit, name='wiki_edit'),
    path('wiki/upload/', wiki.wiki_upload, name='wiki_upload'),
]

urlpatterns = [
    # 登录、注册(含验证)
    path('authcode/email/', account.auth_code_email, name='auth_code_email'),
    path('authcode/image/', account.auth_code_image, name='auth_code_image'),
    path('authcode/sms/', account.auth_code_sms,
         name='auth_code_sms'),  # short message service
    path('index/', home.index, name='index'),
    path('login/', account.login, name='login'),  # 用户名或邮箱 密码登录
    path('login/email/', account.login_email, name='login_email'),  # 邮箱验证码登录
    path('login/sms/', account.login_sms, name='login_sms'),  # 手机验证码登录
    path('logout/', account.logout, name='logout'),
    path('register/', account.register, name='register'),

    # 项目列表
    path('project/list/', project.project_list, name='project_list'),
    # 因为这里使用的 str 路径转换器,理论上我们应该限制新建项目的名称不可以
    # 包含斜杠 '/', 使用 slug 路径转换器则没有限制
    path('project/star/<str:project_type>/<int:project_id>/',
         project.project_star,
         name='project_star'),
    path('project/unstar/<str:project_type>/<int:project_id>/',
         project.project_unstar,
         name='project_unstar'),

    # 单独项目
    path('manage/<int:project_id>/', include(manage_patterns)),

    path('invite/join/<int:code>/', issues.invite_join, name='invite_join'),

    # 价格、支付
    path('price/', home.price, name='price'),
    path('payment/<int:policy_id>/', home.payment, name='payment'),

    path('pay/', home.pay, name='pay'),
    path('pay/notify/', home.pay_notify, name='pay_notify'),

]
